{% extends 'users/base.html' %}
{% load static %}
{% load form_helpers %}

{% block title %}User Key{% endblock %}

{% block usercontent %}
    {% if object.is_active %}
        <div class="alert alert-danger" role="alert">
            <strong>Warning:</strong> Changing your public key will require your user key to be re-activated by another
            user. You will be unable to retrieve any secrets until your key has been reactivated.
        </div>
    {% endif %}
    <form action="." method="post" class="form">
        {% csrf_token %}
        <div class="form-group">
            {% render_field form.public_key %}
        </div>
        <div class="row">
            <div class="form-group">
                <div class="col-sm-6 col-md-6">
                    <button type="button" class="btn btn-info" id="generate_keypair">Generate a New Key Pair</button>
                </div>
                <div class="col-sm-6 col-md-6 text-right">
                    <button type="submit" name="_update" class="btn btn-primary">Save</button>
                    <a href="{% url 'user:userkey' %}" class="btn btn-default">Cancel</a>
                </div>
            </div>
        </div>
    </form>
    <div class="modal fade" id="new_keypair_modal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-md" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="new_keypair_modal_title">
                        New RSA Key Pair
                    </h4>
                </div>
                <div class="modal-body">
                    <strong>New Public Key</strong>
                    <div class="form-group">
                        <textarea class="form-control" id="new_pubkey" style="height: 250px;"></textarea>
                    </div>
                    <strong>New Private Key</strong>
                    <div class="form-group">
                        <textarea class="form-control" id="new_privkey" style="height: 250px;"></textarea>
                    </div>
                </div>
                <div class="modal-footer text-center">
                    <button type="button" class="btn btn-danger" id="use_new_pubkey" data-dismiss="modal">I have saved my new private key</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block javascript %}
<script src="{% static 'js/secrets.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}
